Skip to content

Only accept a tuple as Any when each of its elements is - #7084

Merged
SeanTAllen merged 1 commit into
mainfrom
fix-7023-tuple-elements-in-top-type
Dec 4, 2026
Merged

SeanTAllen merged 1 commit into
mainfrom
fix-7023-tuple-elements-in-top-type

Conversation

@SeanTAllen

Copy link
Copy Markdown
Member

A tuple was a subtype of Any, or of any other interface with no methods, whenever its capability fit. is_tuple_sub_nominal never looked at the elements. So a tuple holding a struct, a bare lambda, a \nosupertype\ type or an unconstrained type parameter could go into Any, even though none of those can go there on its own. That's where three bugs came from: matching a boxed tuple with a bare lambda element segfaulted (#7023), sending a tuple with a struct element to an Any val parameter hung or segfaulted in the GC (#6770), and a tuple pattern with a \nosupertype\ element tripped an assertion in is_nominal_match_tuple that assumed every element could come out of a top type (#7024).

The rule now is the one the element already has on its own: a tuple is a subtype of a top type only if each element is, checked with is_x_sub_x with capability ignored, since the tuple's capability is checked separately. is_nominal_match_tuple turns the old assertion into a "can never match" answer, and it looks for such an element before it reports a capability or descriptor problem, so the order of the elements doesn't change the result. could_be_subtype_ignore_cap, which decides whether a pattern's type argument could unify with a type parameter's constraint, gets a tuple case to go with the new rule. Without it, Box[(A, U32)] against Box[X: Any val] would become "this pattern can never match".

This rejects programs that compile today: a tuple with a struct (including Pointer and NullablePointer), bare, \nosupertype\ or unconstrained type parameter element put into Any, or used as a type argument constrained by Any. Each of those elements is already rejected on its own by the same rule, so I'm not opening a tracking issue for them. The release note has the migrations. Two runtime changes come with it in programs that still compile: an iftype testing such a tuple against Any takes its else branch, and a match on a union holding such a tuple no longer takes an Any case for it.

Closes #7023
Closes #7024
Closes #6770

is_tuple_sub_nominal accepted any tuple as a subtype of a top type and
checked only the tuple's capability. A tuple could hold a struct, a bare
lambda, a \nosupertype\ type or an unconstrained type parameter and still
go into Any, though none of those can on its own. Matching such a tuple
out of Any segfaulted, sending one with a struct element to an Any val
parameter hung in the GC, and a tuple pattern with a \nosupertype\ element
tripped an assertion in is_nominal_match_tuple.

Each element must now be a subtype of the top type on its own, ignoring
capability. is_nominal_match_tuple treats such an element as "can never
match" and lets it win over a capability or descriptor denial from
another element. could_be_subtype_ignore_cap gets a tuple case so that
type-argument patterns like Box[(A, U32)] against Box[X: Any val] still
unify.

Closes #7023
Closes #7024
Closes #6770
@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label Dec 4, 2026
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Dec 4, 2026
@SeanTAllen
SeanTAllen merged commit 8e048d6 into main Dec 4, 2026
17 checks passed
@SeanTAllen
SeanTAllen deleted the fix-7023-tuple-elements-in-top-type branch December 4, 2026 07:07
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Dec 4, 2026
github-actions Bot pushed a commit that referenced this pull request Dec 4, 2026
github-actions Bot pushed a commit that referenced this pull request Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge

Projects

None yet

2 participants